package com.wxh.excel;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;


/**
 * @ClassName: ExcelStyle
 * @Description: exceL样式类
 * @Author wxh
 * @Date: 2019/11/5 10:18
 * @Version V1.0.0
 * @Since 1.8
 */
public class ExcelStyle {


    /**
     * 字体
     * 红色9号  微软雅黑
     * @param workBook 工作簿对象
     * @return XSSFFont 字体对象
     */
    public static XSSFFont getFontDisqualification(XSSFWorkbook workBook) {
        XSSFFont font_disqualification = workBook.createFont();
        font_disqualification.setColor(Font.COLOR_RED);
        font_disqualification.setFontName("微软雅黑");
        //设置字体大小
        font_disqualification.setFontHeightInPoints((short) 9);
        return font_disqualification;
    }


    /**
     * 字体
     * 橙色 9号 微软雅黑
     * @param workBook 工作簿对象
     * @return XSSFFont 字体对象
     */
    public static XSSFFont getFontBetween(XSSFWorkbook workBook) {
        XSSFFont font_betweem = workBook.createFont();
        font_betweem.setColor(IndexedColors.ORANGE.getIndex());
        font_betweem.setFontName("微软雅黑");
        //设置字体大小
        font_betweem.setFontHeightInPoints((short) 9);
        return font_betweem;
    }


    /**
     * 字体
     * 默认黑色 12号 微软雅黑
     * @param workBook 工作簿对象
     * @return XSSFFont 字体对象
     */
    public static XSSFFont getFontCommon(XSSFWorkbook workBook) {
        XSSFFont font_common = workBook.createFont();
        font_common.setFontName("微软雅黑");
        //设置字体大小
        font_common.setFontHeightInPoints((short) 9);
        return font_common;
    }


    /**
     * 字体
     * 默认黑色 9号 微软雅黑
     * @param workBook 工作簿对象
     * @return XSSFFont 字体对象
     */
    public static XSSFFont getFontCommon2(XSSFWorkbook workBook) {
        XSSFFont font_common = workBook.createFont();
        font_common.setFontName("微软雅黑");
        //设置字体大小
        font_common.setFontHeightInPoints((short) 12);
        return font_common;
    }

    /**
     * 常规样式
     * 垂直居中、微软雅黑9号字体、无背景色
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getGeneralStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        //下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);

        // 水平对方式为：居中
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        //垂直对方式为：居中
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        //设置字体大小颜色
        regionStyle.setFont(getFontCommon(workBook));
        //自动换行
        regionStyle.setWrapText(true);

        DataFormat  format = workBook.createDataFormat();
        // 设置导出单元格的格式为文本格式
        regionStyle.setDataFormat(format.getFormat("@"));
        return regionStyle;
    }


    /**
     * 省级
     * 介于两者之间的数据所需样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getProvinceBetweenStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle province_between_Style = workBook.createCellStyle();
        //下边框
        province_between_Style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        province_between_Style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        province_between_Style.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        province_between_Style.setBorderRight(XSSFCellStyle.BORDER_THIN);

        //居中
        province_between_Style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        province_between_Style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        province_between_Style.setFont(getFontBetween(workBook));

        // 设置背景色
        province_between_Style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
        province_between_Style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        province_between_Style.setWrapText(true);
        return province_between_Style;
    }


    /**
     * 省级
     * 正常数据所需的样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getProvinceStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle provinceStyle = workBook.createCellStyle();
        //下边框
        provinceStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        provinceStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        provinceStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        provinceStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //居中
        provinceStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        provinceStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        provinceStyle.setFont(getFontCommon(workBook));
        // 设置背景色
        provinceStyle.setFillForegroundColor(IndexedColors.RED
                .getIndex());
        provinceStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        provinceStyle.setWrapText(true);
        return provinceStyle;
    }


    /**
     * 省级
     * 数据不合格所需要的样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getProvinceDisqualificationStyle(XSSFWorkbook workBook) {
        XSSFCellStyle province_disqualification_Style = workBook.createCellStyle();
        province_disqualification_Style.setFont(getFontDisqualification(workBook));
        //下边框
        province_disqualification_Style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        province_disqualification_Style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        province_disqualification_Style.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        province_disqualification_Style.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //居中
        province_disqualification_Style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        province_disqualification_Style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        // 设置背景色
        province_disqualification_Style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE
                .getIndex());
        province_disqualification_Style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        province_disqualification_Style.setWrapText(true);
        return province_disqualification_Style;
    }


    /**
     * 地市级
     * 正常数据所需要的样式  单元格格式为常规
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getRegionStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        //下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);

        //水平对方式为：居中
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        //垂直对方式为：居中
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        regionStyle.setFont(getFontCommon(workBook));
        regionStyle.setWrapText(true);

        return regionStyle;
    }

    /**
     * 蓝色背景样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getBlueBackgroundStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        //下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        // 设置背景色
        regionStyle.setFillForegroundColor(IndexedColors.BLUE
                .getIndex());
        regionStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        //水平对方式为：居中
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        //垂直对方式为：居中
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        regionStyle.setFont(getFontCommon(workBook));
        regionStyle.setWrapText(true);

        return regionStyle;
    }


    /**
     * 地市级
     * 正常数据所需要的样式  单元格格式为常规
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getTestStyle1(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        // /下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        //左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        //上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        //右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);

        regionStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 128, 128)));
        regionStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        return regionStyle;
    }

    /**
     * 地市级
     * 正常数据所需要的样式  单元格格式为文本
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getRegionStyle2(XSSFWorkbook workBook) {
        // 设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        // 下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        // 左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        // 上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        // 右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        // 居中
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        regionStyle.setFont(getFontCommon(workBook));
        regionStyle.setWrapText(true);

        DataFormat  format = workBook.createDataFormat();
        //设置导出单元格的格式为文本格式
        regionStyle.setDataFormat(format.getFormat("@"));

        return regionStyle;
    }

    /**
     * 地市级
     * 正常数据所需要的样式  单元格格式为文本
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getRegionStyle3(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        // 下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        // 左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        // 上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        // 右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //左对齐
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        regionStyle.setFont(getFontCommon2(workBook));
        regionStyle.setWrapText(true);

        DataFormat  format = workBook.createDataFormat();
        //设置导出单元格的格式为文本格式
        regionStyle.setDataFormat(format.getFormat("@"));

        return regionStyle;
    }


    /**
     * 地市级
     * 正常数据所需要的样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getTestStyle(XSSFWorkbook workBook) {
        //设置属性province(省级)
        XSSFCellStyle regionStyle = workBook.createCellStyle();
        // 下边框
        regionStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        // 左边框
        regionStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        // 上边框
        regionStyle.setBorderTop(XSSFCellStyle.BORDER_THIN);
        // 右边框
        regionStyle.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //左对齐
        regionStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
        regionStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        regionStyle.setFont(getFontCommon(workBook));
        regionStyle.setWrapText(true);

        return regionStyle;
    }


    /**
     * 地市级
     * 不合格数据所需要的样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle 单元格样式对象
     */
    public static XSSFCellStyle getRegionDisqualificationStyle(XSSFWorkbook workBook) {
        XSSFCellStyle region_disqualification_Style = workBook.createCellStyle();
        region_disqualification_Style.setFont(getFontDisqualification(workBook));
        // 下边框
        region_disqualification_Style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        // 左边框
        region_disqualification_Style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        // 上边框
        region_disqualification_Style.setBorderTop(XSSFCellStyle.BORDER_THIN);
        // 右边框
        region_disqualification_Style.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //左对齐
        region_disqualification_Style.setAlignment(XSSFCellStyle.ALIGN_LEFT);
        region_disqualification_Style.setAlignment(XSSFCellStyle.ALIGN_CENTER);//居中
        region_disqualification_Style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        region_disqualification_Style.setWrapText(true);
        return region_disqualification_Style;
    }

    /**
     * 地市级
     * 介于两者之间的数据所需样式
     * @param workBook 工作簿对象
     * @return XSSFCellStyle  单元格样式对象
     */
    public static XSSFCellStyle getRegionBetweenStyle(XSSFWorkbook workBook) {
        XSSFCellStyle region_between_Style = workBook.createCellStyle();
        region_between_Style.setFont(getFontBetween(workBook));
        // 下边框
        region_between_Style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        // 左边框
        region_between_Style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        // 上边框
        region_between_Style.setBorderTop(XSSFCellStyle.BORDER_THIN);
        // 右边框
        region_between_Style.setBorderRight(XSSFCellStyle.BORDER_THIN);
        //水平对齐方式  水平居中
        region_between_Style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        //垂直对齐方式  垂直居中
        region_between_Style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);

        region_between_Style.setWrapText(true);

        return region_between_Style;
    }


}